package com.jsyl.dao.authority;

import com.jsyl.dao.base.BaseDao;
import com.jsyl.entity.authority.AvailableVisualProjects;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *
 */
@Repository
public class AvailableVisualProjectsDao extends BaseDao<AvailableVisualProjects> {



    //获得已经做完题目的
    public Integer getMaxCycleId(Integer childId) {
        StringBuilder sql = new StringBuilder(" select max(cycle_id) as CYCLEID from available_visual_projects where child_id=:childId");
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (null!=childId){
            paramMap.put("childId", childId);
        }
        logger.info("SQL : " + "\"" + sql.toString() + "\"");
        List<Map<String, Object>> resultList = namedTemplate.queryForList(sql.toString(), paramMap);
        return (Integer) resultList.get(0).get("CYCLEID");
    }


    //获得已经做完题目的
    public AvailableVisualProjects getMaxCycle(Integer childId,String code) {
        StringBuilder sql = new StringBuilder(" select max(cycle_id) as CYCLEID ,id ad ID,training_times as TRAINING_TIMES," +
                "trained_times as TRAINED_TIMES,priority as PRIORITY, is_finished as IS_FINISHED,child_id as CHILD_ID,project_code AS PROJECT_ID,"+
                "from available_visual_projects where child_id=:childId and project_code =:code ");
        Map<String, Object> paramMap = new HashMap<String, Object>();
        if (null!=childId){
            paramMap.put("childId", childId);
            paramMap.put("code", code);
        }
        logger.info("SQL : " + "\"" + sql.toString() + "\"");
        List<Map<String, Object>> resultList = namedTemplate.queryForList(sql.toString(), paramMap);
        AvailableVisualProjects projects = new AvailableVisualProjects();
        projects.setCycleId((Integer) resultList.get(0).get("CYCLEID"));
        projects.setId((Integer) resultList.get(0).get("ID"));
        projects.setTrainingTimes((Integer) resultList.get(0).get("TRAINING_TIMES"));
        projects.setTrainedTimes((Integer) resultList.get(0).get("TRAINED_TIMES"));
        projects.setPriority((Integer) resultList.get(0).get("PRIORITY"));
        projects.setIsFinished((Integer) resultList.get(0).get("IS_FINISHED"));
        projects.setChildId((Integer) resultList.get(0).get("CHILD_ID"));
        projects.setProjectCode((String) resultList.get(0).get("PROJECT_ID"));
        return projects;
    }

}

